home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-01-21 | 23.9 KB | 932 lines |
- /*
- * ReadDocJ
- *
- * Used to read PilotDocs.
- *
- */
-
- import java.io.*;
- import java.util.*;
- import java.awt.*;
- import java.awt.event.*;
-
- import javax.swing.*;
- import javax.swing.event.*;
- import javax.swing.text.*;
-
- import gnu.regexp.*;
-
- /**
- * <code>BookMarkHelperRD</code> class is used to add the necessary support for ReadDocJ
- * @author Jeffrey A. Krzysztow
- * @version 1.1
- */
- class BookMarkHelperRD extends BookMark {
-
- BookMarkHelperRD() {
- super();
- ok2Save = true;
- }
-
- BookMarkHelperRD(boolean ok2Save) {
- super();
- this.ok2Save = ok2Save;
- }
-
- /**
- * returns whether it is ok to save this bookmark to the external bookmark file
- * @returns true if ok to save bookmark
- * @since 1.1
- */
- public boolean isOk2Save() {
- return ok2Save;
- }
-
- /**
- * sets whether it is ok to save this bookmark
- * @param ok2Save whether it is ok to save this bookmark
- * @since 1.1
- */
- public void setOk2Save(boolean ok2Save) {
- this.ok2Save = ok2Save;
- }
-
- /**
- * returns the string representation "we" want
- * used by JList for holding bookmarks
- * @returns the name of the bookmark
- * @since 1.0
- */
- public String toString() {
- return name;
- }
-
- private boolean ok2Save = false;
- }
-
- /**
- * <code>ReadDocJ</code> is the main application to read PilotDoc files
- * @author Jeffrey A. Krzysztow
- * @version 1.2
- */
- public final class ReadDocJ extends JFrame {
- private final static float version = (float) 1.2;
-
- /**
- * <code>SearchDlg</code> class maintains the search (find) dialog
- * @author Jeffrey A. Krzysztow
- * @since 1.0
- */
- class SearchDlg extends JDialog implements ItemListener, KeyListener {
- HorizontalButtons buttons = new HorizontalButtons();
- JTextField searchFor = new JTextField(30);
- JCheckBox regex = new JCheckBox("Regular expression");
- JCheckBox nocase = new JCheckBox("Case insensitive");
-
- /**
- * Constructs the search dialog
- * @param frame the parent frame
- * @since 1.0
- */
- SearchDlg(JFrame frame) {
- super(frame, false);
-
- setTitle("Search");
-
- GridBagLayout gbl = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- Container contentPane = getContentPane();
-
- contentPane.setLayout(gbl);
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- dispose();
- }
- }
- );
-
- setResizable(false);
-
- JButton button = null;
-
- button = new JButton("Find");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- find();
- }
- }
- );
- button.addKeyListener(this);
- buttons.add(button);
-
- regex.addItemListener(this);
- buttons.add(regex);
-
- nocase.addItemListener(this);
- buttons.add(nocase);
-
- searchFor.addKeyListener(this);
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbl.setConstraints(searchFor, gbc);
- contentPane.add(searchFor);
-
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbl.setConstraints(buttons, gbc);
- contentPane.add(buttons);
-
- pack();
-
- // Center dialog to parent frame
- Point location = frame.getLocation();
- Dimension outerSize = frame.getSize();
- Dimension size = getSize();
- location.x = location.x + (outerSize.width - size.width) / 2;
- location.y = location.y + (outerSize.height - size.height) / 2;
- setLocation(location);
- }
-
- /**
- * handles to find button to search for text
- * @since 1.0
- */
- final void find() {
- String text = searchFor.getText();
- if(text != null) {
- if(regex.isSelected()) {
- try {
- RE searchRegex = new RE(text, RE.REG_MULTILINE | (nocase.isSelected() ? RE.REG_ICASE : 0));
- try {
- REMatch reMatch = searchRegex.getMatch(docText, doc.getCaretPosition() + 1);
- if(reMatch.getStartIndex() > -1) {
- doc.setCaretPosition(reMatch.getStartIndex());
- doc.select(reMatch.getStartIndex(), reMatch.getEndIndex() - reMatch.getStartIndex());
- }
- }
- catch(IllegalArgumentException e) {
- }
- }
- catch(REException e) {
- }
- }
- else {
- int pos = docText.indexOf(text);
- if(pos > 0) {
- doc.setCaretPosition(pos);
- doc.select(pos, pos + text.length());
- }
- }
- }
- }
-
- /**
- * implements ItemListener interface
- * @param e ItemEvent
- * @see java.event.ItemListener#itemStateChanged
- * @since 1.0
- */
- public void itemStateChanged(ItemEvent e) {
- /*
- if(e.getSource() == regex) {
- if(e.getStateChange() == ItemEvent.SELECTED) {
- nocase.setEnabled(true);
- }
- else if(e.getStateChange() == ItemEvent.DESELECTED) {
- nocase.setEnabled(false);
- }
- }
- else if(e.getSource() == nocase) {
- if(e.getStateChange() == ItemEvent.SELECTED) {
- regex.setEnabled(true);
- }
- else if(e.getStateChange() == ItemEvent.DESELECTED) {
- regex.setEnabled(true);
- }
- }
- */
- }
-
- /**
- * implements KeyListener interface
- * @param e KeyEvent
- * @see java.event.KeyListener#keyPressed
- * @since 1.0
- */
- public void keyPressed(KeyEvent e) {
- if(e.getKeyCode() == KeyEvent.VK_ENTER) {
- find();
- }
- }
-
- /**
- * implements KeyListener interface
- * @param e KeyEvent
- * @see java.event.KeyListener#keyReleased
- * @since 1.0
- */
- public void keyReleased(KeyEvent e) {
- }
-
- /**
- * implements KeyListener interface
- * @param e KeyEvent
- * @see java.event.KeyListener#keyTyped
- * @since 1.0
- */
- public void keyTyped(KeyEvent e) {
- }
-
- }
-
- /**
- * <code>BookMarkDlg</code> class maintains the bookmark dialog
- * @author Jeffrey A. Krzysztow
- * @version 1.1
- */
- class BookMarkDlg extends JDialog implements MouseListener, KeyListener {
- HorizontalButtons buttons = new HorizontalButtons();
- JList list = new JList();
- JTextField bookmarkName = new JTextField(16);
-
- /**
- * Constructs the bookmark dialog
- * @param frame the parent frame
- * @since 1.0
- */
- BookMarkDlg(JFrame frame) {
- super(frame, false);
-
- setTitle("Bookmarks");
-
- GridBagLayout gbl = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- Container contentPane = getContentPane();
-
- contentPane.setLayout(gbl);
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- dispose();
- }
- }
- );
- setResizable(false);
-
- JButton button = null;
-
- button = new JButton("Go");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- go();
- }
- }
- );
- buttons.add(button);
-
- button = new JButton("Add");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- add();
- }
- }
- );
- buttons.add(button);
-
- button = new JButton("Delete");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- delete();
- }
- }
- );
- buttons.add(button);
-
- bookmarkName.addKeyListener(this);
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbl.setConstraints(bookmarkName, gbc);
- contentPane.add(bookmarkName);
-
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbl.setConstraints(buttons, gbc);
- contentPane.add(buttons);
-
- list.setPrototypeCellValue("MMMMMMMMMMMMMMMM");
- list.setVisibleRowCount(10);
- list.addKeyListener(this);
- list.addMouseListener(this);
- JScrollPane scrollList = new JScrollPane(list);
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbl.setConstraints(scrollList, gbc);
- contentPane.add(scrollList);
-
- pack();
-
- // Center dialog to parent frame
- Point location = frame.getLocation();
- Dimension outerSize = frame.getSize();
- Dimension size = getSize();
- location.x = location.x + (outerSize.width - size.width) / 2;
- location.y = location.y + (outerSize.height - size.height) / 2;
- setLocation(location);
- }
-
- /**
- * handles the go button to go to the bookmark specified
- * @since 1.0
- */
- final void go() {
- BookMarkHelperRD bm = null;
- String lookingFor = bookmarkName.getText();
- int t = list.getModel().getSize();
- for(int i = 0; i < t; i++) {
- bm = (BookMarkHelperRD)bookmarks.elementAt(i);
- if(lookingFor.equals(bm.name)) {
- try {
- int offset = doc.getLineStartOffset(doc.getLineOfOffset(bm.fileOffset));
- Rectangle startLocation = doc.modelToView(offset);
- JViewport viewPort = scrollDoc.getViewport();
- viewPort.setViewPosition(new Point(startLocation.x, startLocation.y));
- }
- catch(BadLocationException e) {
- System.err.println(e);
- }
- getParent().requestFocus();
- break;
- }
- }
- }
-
- /**
- * handles to add button to add the specified bookmark
- * @since 1.0
- */
- final void add() {
- String lookingFor = bookmarkName.getText();
- BookMarkHelperRD bm = null;
- int t = bookmarks.size();
- boolean addBookmark = true;
- for(int i = 0; i < t; i++) {
- bm = (BookMarkHelperRD)bookmarks.elementAt(i);
- if(lookingFor.equals(bm.name)) {
- addBookmark = false;
- break;
- }
- }
- if(addBookmark) {
- bm = new BookMarkHelperRD();
- bm.name = lookingFor;
- bm.fileOffset = doc.getCaretPosition();
- bookmarks.addElement(bm);
- }
- else {
- status.setText("Bookmark name already in use");
- }
- }
-
- /**
- * handles the delete button to delete the specified bookmark
- * @since 1.0
- */
- final void delete() {
- BookMarkHelperRD bm = null;
- String lookingFor = bookmarkName.getText();
- int t = bookmarks.size();
- for(int i = 0; i < t; i++) {
- bm = (BookMarkHelperRD)bookmarks.elementAt(i);
- if(lookingFor.equals(bm.name)) {
- bookmarks.removeElement(bm);
- bookmarkName.setText("");
- break;
- }
- }
- }
-
- /**
- * updates the list of bookmarks
- * @since 1.0
- */
- public void updateBookmarks() {
- list.setModel(bookmarks);
- }
-
- /**
- * implements MouseListener interface
- * @param e MouseEvent
- * @see java.event.MouseListerner#mouseClicked
- * @since 1.0
- */
- public void mouseClicked(MouseEvent e) {
- if(e.getClickCount() == 2) {
- bookmarkName.setText(((BookMarkHelperRD)list.getSelectedValue()).name);
- go();
- }
- }
-
- /**
- * implements MouseListener interface
- * @param e MouseEvent
- * @see java.event.MouseListerner#mouseEntered
- * @since 1.0
- */
- public void mouseEntered(MouseEvent e) {
- }
-
- /**
- * implements MouseListener interface
- * @param e MouseEvent
- * @see java.event.MouseListerner#mouseExited
- * @since 1.0
- */
- public void mouseExited(MouseEvent e) {
- }
-
- /**
- * implements MouseListener interface
- * @param e MouseEvent
- * @see java.event.MouseListerner#mousePressed
- * @since 1.0
- */
- public void mousePressed(MouseEvent e) {
- }
-
- /**
- * implements MouseListener interface
- * @param e MouseEvent
- * @see java.event.MouseListerner#mouseReleased
- * @since 1.0
- */
- public void mouseReleased(MouseEvent e) {
- }
-
- /**
- * implements KeyListener interface
- * @param e KeyEvent
- * @see java.event.KeyListener#keyPressed
- * @since 1.0
- */
- public void keyPressed(KeyEvent e) {
- if(e.getKeyCode() == KeyEvent.VK_ENTER) {
- go();
- }
- }
-
- /**
- * implements KeyListener interface
- * @param e KeyEvent
- * @see java.event.KeyListener#keyReleased
- * @since 1.0
- */
- public void keyReleased(KeyEvent e) {
- }
-
- /**
- * implements KeyListener interface
- * @param e KeyEvent
- * @see java.event.KeyListener#keyTyped
- * @since 1.0
- */
- public void keyTyped(KeyEvent e) {
- }
-
- }
-
- HorizontalButtons buttons = new HorizontalButtons();
- JTextArea doc = new JTextArea(20, 40);
- JScrollPane scrollDoc = new JScrollPane(doc) {
- Dimension preferredSize;
- public Dimension getPreferredSize() {
- return getViewport().getPreferredSize();
- }
- };
- JLabel status = new JLabel();
-
- String docText = null;
- DefaultListModel bookmarks = new DefaultListModel();
- int embeddedBookmarks = 0;
- File pilotDoc = new File(".");
- File pilotDocBM = null;
- DatabaseHeader dbHeader = new DatabaseHeader();
-
- SearchDlg searchDlg = null;
- BookMarkDlg bookmarkDlg = null;
-
- /**
- * Constructs the main frame of the application
- * @param s title
- * @since 1.0
- */
- ReadDocJ(String s) {
- super(s);
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- shutdown();
- }
- }
- );
-
- setResizable(false);
-
- GridBagLayout gbl = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- Container contentPane = getContentPane();
-
- contentPane.setLayout(gbl);
-
- JButton button = null;
-
- button = new JButton("Open");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- open();
- }
- }
- );
- button.setMnemonic('o');
- buttons.add(button);
-
- button = new JButton("Search");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- search();
- }
- }
- );
- button.setMnemonic('s');
- buttons.add(button);
-
- button = new JButton("Bookmarks");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- bookmarks();
- }
- }
- );
- button.setMnemonic('b');
- buttons.add(button);
-
- button = new JButton("Top");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- top();
- }
- }
- );
- button.setMnemonic('t');
- buttons.add(button);
-
- button = new JButton("Bottom");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- bottom();
- }
- }
- );
- button.setMnemonic('m');
- buttons.add(button);
-
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbc.fill = GridBagConstraints.BOTH;
- gbl.setConstraints(buttons, gbc);
- contentPane.add(buttons);
-
- doc.setEditable(false);
- doc.setWrapStyleWord(true);
- doc.setLineWrap(true);
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbc.fill = GridBagConstraints.BOTH;
- gbl.setConstraints(scrollDoc, gbc);
- contentPane.add(scrollDoc);
-
- status.setText("ReadDocJ v" + version);
- gbc.gridx = GridBagConstraints.REMAINDER;
- gbc.fill = GridBagConstraints.BOTH;
- gbl.setConstraints(status, gbc);
- contentPane.add(status);
-
- pack();
- show();
-
- // Center frame to screen
- Point location = getLocation();
- Dimension outerSize = getToolkit().getScreenSize();
- Dimension size = getSize();
- location.x = location.x + (outerSize.width - size.width) / 2;
- location.y = location.y + (outerSize.height - size.height) / 2;
- setLocation(location);
-
- searchDlg = new SearchDlg(this);
-
- bookmarkDlg = new BookMarkDlg(this);
- }
-
- /**
- * application start
- * @param args command line arguments
- * @since 1.0
- */
- public static void main(String[] args) {
- ReadDocJ rdj = new ReadDocJ("ReadDocJ v" + version + " - no document");
- }
-
- /**
- * shuts downs the application
- * @since 1.0
- */
- final void shutdown() {
- saveExternalBookmarks();
- System.exit(0);
- }
-
- /**
- * handles the open button to open a PilotDoc file
- * @since 1.0
- */
- final void open() {
- status.setText(" ");
- saveExternalBookmarks();
- JFileChooser fc = new JFileChooser(pilotDoc);
- ExampleFileFilter filter = new ExampleFileFilter(new String [] { "prc", "pdb" }, "PilotDoc Files");
- fc.setFileFilter(filter);
- if(fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
- setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- pilotDoc = fc.getSelectedFile();
- pilotDocBM = new File(pilotDoc.getParent(), pilotDoc.getName() + ".bm");
- try {
- RandomAccessFile fin = null;
- fin = new RandomAccessFile(pilotDoc, "r");
- byte[] buffer = decode(fin, pilotDoc, dbHeader);
- fin.close();
- if(null != buffer) {
- docText = new String(buffer);
-
- processEmbeddedBookmarks();
-
- loadExternalBookmarks();
-
- bookmarkDlg.updateBookmarks();
-
- doc.setText(docText);
- doc.setCaretPosition(0);
- setTitle("ReadDocJ v" + version +" - " + dbHeader.name);
- }
- }
- catch(FileNotFoundException e) {
- status.setText("The file " + pilotDoc.getName() + " could not be found");
- JOptionPane.showMessageDialog(this, "The file " + pilotDoc.getName() + " could not be found\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
- return;
- }
- catch(IOException e) {
- status.setText("Error accessing file " + pilotDoc.getName());
- JOptionPane.showMessageDialog(this, "Error accessing file " + pilotDoc.getName() + "\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
- }
- setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- }
- }
-
- /**
- * handles the search button to present the search dialog
- * @since 1.0
- */
- final void search() {
- if(searchDlg != null) {
- searchDlg.show();
- }
- }
-
- /**
- * handles the bookmark button to present the bookmark dialog
- * @since 1.0
- */
- final void bookmarks() {
- if(bookmarkDlg != null) {
- bookmarkDlg.show();
- }
- }
-
- /**
- * handles the top button to go to the top of the PilotDoc
- * @since 1.1
- */
- final void top() {
- if(docText != null) {
- doc.setCaretPosition(0);
- }
- }
-
- /**
- * handles the bottom button to go to the bottom of the PilotDoc
- * @since 1.1
- */
- final void bottom() {
- if(docText != null) {
- doc.setCaretPosition(docText.length());
- }
- }
-
- /**
- * decodes the PilotDoc file
- * @param fin RandomAccessFile to the PilotDoc file
- * @param file File to the PilotDocs file
- * @param dbHeader returns the DatabaseHeader record, must be created by caller
- * @returns byte array of PilotDoc decoded
- * @throws IOException to the caller can handle any I/O errors
- * @since 1.0
- */
- final byte[] decode(final RandomAccessFile fin, final File file, DatabaseHeader dbHeader) throws IOException {
- status.setText("Processing database header");
- dbHeader.read(fin);
-
- if(dbHeader.creatorID != DatabaseHeader.ReaderID
- && dbHeader.creatorID != DatabaseHeader.TealDocID
- || dbHeader.typeID != DatabaseHeader.TEXt) {
- status.setText(file.getName() + "is unknown format");
- return null;
- }
-
- RecordIndex[] ri = new RecordIndex[dbHeader.numRecords];
- for(int i = 0; i < dbHeader.numRecords; i++) {
- status.setText("Processing record index " + i + " of " + dbHeader.numRecords);
- ri[i] = new RecordIndex();
- ri[i].read(fin);
- }
-
- short unknown = fin.readShort();
-
- DocumentHeader docHeader = new DocumentHeader();
- status.setText("Processing document header");
- fin.seek(ri[0].fileOffset);
- docHeader.read(fin);
-
- if(docHeader.version != DocumentHeader.UNCOMPRESSED && docHeader.version != DocumentHeader.COMPRESSED) {
- status.setText(file.getName() + " unknown file compression type: " + docHeader.version);
- return null;
- }
-
- byte[] buffer = new byte[docHeader.numRecords * DocumentHeader.textRecordSize];
- // the DocumentHeader.storyLen is not always correct, so this is over-kill
-
- boolean compressed = (docHeader.version == DocumentHeader.COMPRESSED);
-
- PilotDocRecord textBuf;
-
- int dwRecLen;
- int bufferPos = 0;
- for(int i = 1; i <= docHeader.numRecords; i++) {
- status.setText("Decoding " + i + " of " + docHeader.numRecords);
- if(i == ri.length - 1) {
- // for the last, use the file len
- dwRecLen = (int) fin.length() - ri[i].fileOffset;
- }
- else {
- dwRecLen = ri[i + 1].fileOffset - ri[i].fileOffset;
- }
- fin.seek(ri[i].fileOffset);
- textBuf = new PilotDocRecord(dwRecLen);
- fin.read(textBuf.buf);
- if(compressed) {
- textBuf.decompress();
- }
- System.arraycopy(textBuf.buf, 0, buffer, bufferPos, textBuf.length());
- bufferPos += textBuf.length();
- }
-
- byte[] newbuffer = new byte[bufferPos];
- System.arraycopy(buffer, 0, newbuffer, 0, bufferPos);
-
- /////////////////////////////////////////////////////////////
- // Handle encoded bookmarks if any
- bookmarks = new DefaultListModel();
- if(docHeader.numRecords + 1 < dbHeader.numRecords) {
- int bmn = 1;
- int bmt = dbHeader.numRecords - docHeader.numRecords - 1;
- for(int i = docHeader.numRecords + 1; i < dbHeader.numRecords; i++, bmn++) {
- status.setText("Processing internal bookmark " + bmn + " of " + bmt);
- fin.seek(ri[i].fileOffset);
- BookMarkHelperRD bm = new BookMarkHelperRD();
- bm.read(fin);
- bookmarks.addElement(bm);
- }
- }
-
- return newbuffer;
- }
-
- /**
- * processes the auto-bookmarks if present
- * @since 1.1
- */
- final void processEmbeddedBookmarks() {
- embeddedBookmarks = 0;
- char curChar;
- int startPos = -1;
- int endPos = -1;
- for(int curCharPos = docText.length() - 1; curCharPos > -1; curCharPos--) {
- curChar = docText.charAt(curCharPos);
- if(curChar == '<') { // start sequence
- startPos = curCharPos;
- break; // we are done looking
- }
- else if(curChar == '>') { // end sequence
- endPos = curCharPos;
- }
- else if(!Character.isWhitespace(curChar) && endPos == -1) {
- break;
- }
- }
- if(startPos > -1 && endPos > -1) {
- String lookFor = docText.substring(startPos + 1, endPos);
- int found = 0;
- while((found = docText.indexOf(lookFor, found)) > 0) {
- if(docText.charAt(found - 1) == '\n') {
- BookMarkHelperRD bm = new BookMarkHelperRD(false);
- bm.fileOffset = found;
- int curCharPos = found += lookFor.length();
- for(; curCharPos < docText.length(); curCharPos++) {
- if(docText.charAt(curCharPos) == '\n') {
- while(Character.isWhitespace(docText.charAt(found))) {
- found++;
- }
- bm.name = docText.substring(found, curCharPos);
- bookmarks.addElement(bm);
- embeddedBookmarks++;
- break;
- }
- }
- found = curCharPos;
- }
- else {
- found++;
- }
- }
- }
- }
-
- final private int bookmarkID = 0x4252534b; // BRSK, so we "know" it's a "valid" bookmark file
-
- /**
- * saves the bookmarks to a file
- * @since 1.0
- */
- final void saveExternalBookmarks() {
- if(pilotDocBM != null && bookmarks.size() - embeddedBookmarks > 0) {
- try {
- pilotDocBM.delete();
- RandomAccessFile bout = new RandomAccessFile(pilotDocBM, "rw");
- BookMarkHelperRD bm = null;
- bout.writeInt(bookmarkID);
- bout.writeInt(bookmarks.size() - embeddedBookmarks);
- int t = bookmarks.size();
- for(int i = 0; i < t; i++) {
- status.setText("Processing external bookmark " + i + " of " + t);
- bm = (BookMarkHelperRD)bookmarks.elementAt(i);
- if(bm.isOk2Save()) {
- bm.write(bout);
- }
- }
- bout.close();
- }
- catch(IOException e) {
- status.setText("Error accessing file " + pilotDocBM.getName());
- JOptionPane.showMessageDialog(this, "Error accessing file " + pilotDocBM.getName() + "\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
-
- /**
- * loads the bookmarks from a file
- * @since 1.0
- */
- final void loadExternalBookmarks() {
- if(pilotDocBM != null) {
- if(pilotDocBM.exists()) {
- if(pilotDocBM.lastModified() >= pilotDoc.lastModified()) {
- try {
- RandomAccessFile bout = new RandomAccessFile(pilotDocBM, "rw");
- if(bout.readInt() == bookmarkID) {
- bookmarks = new DefaultListModel();
- BookMarkHelperRD bm = null;
- int count = bout.readInt();
- for(int x = 0; x < count; x++) {
- status.setText("Processing external bookmark " + x + " of " + count);
- bm = new BookMarkHelperRD();
- bm.read(bout);
- bookmarks.addElement(bm);
- }
- }
- bout.close();
- }
- catch(IOException e) {
- status.setText("Error accessing file " + pilotDocBM.getName());
- JOptionPane.showMessageDialog(this, "Error accessing file " + pilotDocBM.getName() + "\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- else {
- status.setText("External bookmark file will not be loaded");
- }
- }
- }
- }
-
- }
-